package com.aistar.service.impl;

import com.aistar.mapper.MemberMapper;
import com.aistar.pojo.Member;
import com.aistar.pojo.MemberExample;
import com.aistar.service.RegistService;
import com.aistar.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RegistServiceImpl implements RegistService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public boolean save(Member member) {
        memberMapper.insert(member);
        return false;
    }

    @Override
    public boolean deleteById(Integer userId) {
        return false;
    }

    @Override
    public Member selectById(Integer userId) {
        return null;
    }

    //根据手机号查询
    @Override
    public JsonResult selectByPhone(Long userTel) {
        Member member = null;
        MemberExample example = new MemberExample();
        MemberExample.Criteria criteria = example.createCriteria();
        criteria.andUserTelEqualTo(userTel);
        List<Member> usersList = memberMapper.selectByExample(example);

        if(usersList.size()>0){
            member = usersList.get(0);
            return new JsonResult(0,"查询到该用户,手机号已使用",member);
        }else {
            return new JsonResult(1,"没有查询到该手机用户",member);
        }
    }

    @Override
    public JsonResult loginByTelno(Long userTel, String userPassword) {
        return null;
    }
}
